package com.hxzy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzy.common.constans.WaimaiConst;
import com.hxzy.common.dto.ChangeStatusDTO;
import com.hxzy.dto.EmployeeSearchDTO;
import com.hxzy.dto.LoginDTO;
import com.hxzy.entity.Employee;
import com.hxzy.mapper.EmployeeMapper;
import com.hxzy.service.EmployeeService;
import com.hxzy.vo.LoginVO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 员工业务逻辑实体类
 * @author Administrator
 */
@Log4j2
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper,Employee> implements EmployeeService {


    @Override
    public List<Employee> search(EmployeeSearchDTO dto) {
        return  super.getBaseMapper().search(dto);
    }

    /**
     * 禁用账户
     * @param ids
     * @return
     */
    @Override
    public int removeByIds(Long[] ids) {
        int count=0;

        if(ids!=null && ids.length>0) {
            List<Long> arr = Arrays.asList(ids);
            if (arr.contains(1L)) {
                arr.remove(1L);
            }
            //循环遍历,向数据发送 ids长度条sql，效率比较低
//            for(Long id : arr){
//               count+= this.employeeMapper.updateStatus(id, WaimaiConst.DISABLE_STATUS);
//            }

            //批量更新
           count= super.getBaseMapper().updateStatusBatch(ids,WaimaiConst.DISABLE_STATUS);

        }
        return count;
    }

    @Override
    public int updateStatus(ChangeStatusDTO changeStatusDTO) {
        return super.getBaseMapper().updateStatus(changeStatusDTO.getId(),changeStatusDTO.getStatus());
    }

    @Override
    public Employee selectByPrimaryKey(Long id) {
        return super.getBaseMapper().selectByPrimaryKey(id);
    }


}
